package tt.com.deadcold.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import tt.com.bodybeautymanager.service.DeadCosmeticService;
import tt.com.common.model.ColdRoom;
import tt.com.common.model.DeadColdRoom;
import tt.com.common.model.DeadCosmetic;
import tt.com.common.util.CommonResult;
import tt.com.common.util.PageUtil;
import tt.com.deadcold.Vo.deadcoldroomVo;
import tt.com.deadcold.service.*;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping(value = "dead/coldroom")
public class DeadColdRoomController {
    @Autowired
    private DeadColdService coldService;
    @Autowired
    private RemainsUnearthed remainsUnearthed;
    @Autowired
    private ColdMoney coldMoney;
    @Autowired
    private DeadColdStatistics statistics;
    @Autowired
    private DeadColdRegister deadColdRegister;

    //显示冷藏信息
    @PostMapping(value = "show/coldroom")
    public ResponseEntity showDeadColdRoom(@RequestBody deadcoldroomVo deadcoldroomVo, HttpServletRequest request) {
        CommonResult result = coldService.showDeadCold(deadcoldroomVo.getPageUtil());
        return new ResponseEntity(result,HttpStatus.valueOf(result.getStatus()));
    }

    //删除
    @PostMapping(value = "delete/coldroom")
    public ResponseEntity deleteById(@RequestBody DeadColdRoom deadColdRoom, HttpServletRequest request) {
        CommonResult result = coldService.deleteDeadcold(deadColdRoom);
        return new ResponseEntity(result,HttpStatus.valueOf(result.getStatus()));
    }

    //修改
    @PostMapping(value = "update/coldroom")
    public ResponseEntity updateById(@RequestBody DeadColdRoom deadColdRoom, HttpServletRequest request) {
        CommonResult result = coldService.updateDeadcold(deadColdRoom);
        return new ResponseEntity(result,HttpStatus.valueOf(result.getStatus()));
    }

    //查询
    @PostMapping(value = "select/coldroom")
    public ResponseEntity selectColdRoom(@RequestBody deadcoldroomVo deadcoldroomVo,HttpServletRequest request){
        CommonResult result = coldService.selectDeadcold(deadcoldroomVo.getDeadColdRoom(),deadcoldroomVo.getPageUtil());
        return new ResponseEntity(result,HttpStatus.valueOf(result.getStatus()));
    }
    //更改出藏状态，记录时间和操作人员
    @PostMapping(value = "update/remains")
    public ResponseEntity updateru(@RequestBody DeadColdRoom deadColdRoom,HttpServletRequest request){
        CommonResult result = remainsUnearthed.updateRutime(deadColdRoom,deadColdRoom.getRefrigerateStatus(),
                deadColdRoom.getLastUpdateTime(),deadColdRoom.getLastUpdateUserId());
        return new ResponseEntity(result,HttpStatus.valueOf(result.getStatus()));
    }

    //冷藏费用计算
    @PostMapping(value = "money/coldroom")
    public ResponseEntity moneycalculation(@RequestBody DeadColdRoom deadColdRoom,HttpServletRequest request){
        CommonResult result = coldMoney.costcalculation(deadColdRoom);
        return new ResponseEntity(result,HttpStatus.valueOf(result.getStatus()));
    }
    //前端页面展示，显示冷藏格未使用的
    @PostMapping(value = "show/room")
    public ResponseEntity showRoom(HttpServletRequest request){
        CommonResult result = statistics.showroom0();
        return new ResponseEntity(result,HttpStatus.valueOf(result.getStatus()));
    }
    //前端页面展示，显示冷藏格已使用的
    @PostMapping(value = "show/rooms")
    public ResponseEntity showRooms(HttpServletRequest request){
        CommonResult result = statistics.showroom1();
        return new ResponseEntity(result,HttpStatus.valueOf(result.getStatus()));
    }
    //前端页面展示，显示冷藏格已使用的信息
    @PostMapping(value = "show/roommessage")
    public ResponseEntity showRoommessage(@RequestBody deadcoldroomVo deadcoldroomVo,HttpServletRequest request){
        CommonResult result = statistics.showroommessage(deadcoldroomVo.getPageUtil());
        return new ResponseEntity(result,HttpStatus.valueOf(result.getStatus()));
    }
    //前端页面展示，显示每日出藏情况
    @PostMapping(value = "show/everycome")
    public ResponseEntity showEverycome(HttpServletRequest request){
        CommonResult result = statistics.showeverydaycome();
        return new ResponseEntity(result,HttpStatus.valueOf(result.getStatus()));
    }
    //前端页面展示，显示每日入藏情况
    @PostMapping(value = "show/everyrnter")
    public ResponseEntity showEveryenter(HttpServletRequest request){
        CommonResult result = statistics.showeverydayenter();
        return new ResponseEntity(result,HttpStatus.valueOf(result.getStatus()));
    }

    //记录时间
    @PostMapping(value = "record/time")
    public ResponseEntity recordTime(DeadColdRoom deadColdRoom, ColdRoom coldRoom,HttpServletRequest request){
        CommonResult result = deadColdRegister.recordtime(deadColdRoom,coldRoom,deadColdRoom.getLastUpdateTime(),deadColdRoom.getLastUpdateUserId());
        return new ResponseEntity(result,HttpStatus.valueOf(result.getStatus()));
    }
}